package com.visikard.response;

import java.util.Locale;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.visikard.application.Constant;

public class RingUpResponse extends BaseResponse {

	public enum RingUpResultEnum {
		SUCCESS, EXPIRED, FAILED
	}

	private RingUpResultEnum result;
	private double amountRedeemed;
	private double previousBalance;
	private int punchRecorded;

	public double getAmountRedeemed() {
		return amountRedeemed;
	}

	public void setAmountRedeemed(double amountRedeemed) {
		this.amountRedeemed = amountRedeemed;
	}

	public double getPreviousBalance() {
		return previousBalance;
	}

	public void setPreviousBalance(double previousBalance) {
		this.previousBalance = previousBalance;
	}

	public int getPunchRecorded() {
		return punchRecorded;
	}

	public void setPunchRecorded(int punchRecorded) {
		this.punchRecorded = punchRecorded;
	}

	public RingUpResultEnum getResult() {
		return result;
	}

	public void setResult(RingUpResultEnum result) {
		this.result = result;
	}

	@Override
	public void extractDataFromServer(String response) throws JSONException {
		super.extractDataFromServer(response);

		if (errorCode == SUCCESS) {
			JSONObject jData = getDataJObject(response);
			String resultStr = jData.getString("result");
			if (resultStr.equalsIgnoreCase("SUCCESS")) {
				result = RingUpResultEnum.SUCCESS;
				amountRedeemed = jData.getDouble("amountRedeemed");
				previousBalance = jData.getDouble("previousBalance");
				punchRecorded = jData.getInt("punkRecorded");
			}
			else if (resultStr.toUpperCase(Locale.US).contains("EXPIRED")) {
				result = RingUpResultEnum.EXPIRED;
			}
			else {
				errorCode = INVALID_RESPONSE;
				errorMsg = "Invalid Response";
			}
		}
		else if (response != null && !response.isEmpty() && response.equals("Not Found")) {
			Log.e(Constant.LOG_TAG, "getGiftKardList: " + "Not Found!!!");
			errorCode = GetGiftKardResponse.ERROR_NOT_FOUND;
			errorMsg = "Not Found";
		}
	}

}
